package com.itheima.map;

/*
模拟斗地主案例的主要步骤
        1.定义一个数组，用于保存牌的花色
        2.定义一个数组，用于保存牌的数字
        3.创建ArrayList集合对象，将花色和数字进行拼接后添加到集合中
        4.调用Collections工具类中的shuffle()方法洗牌
        5.创建三个玩家集合一个底牌集合，进行发牌动作
        6.遍历玩家和底牌的集合，查看内容
*/

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class DouDiZhuDemo1 {
    public static void main(String[] args) {
    String[] s={"♠","♥","♦","♣"};
    String[] s1={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
    String s3="大王";
    String s4="小王";
        ArrayList<String> arrayList=new ArrayList<String>();
        System.out.println(s1.length);
        for (int i = 0; i < s.length; i++) {
            for (int i1 = 0; i1 < s1.length; i1++) {
                StringBuilder sb=new StringBuilder();
                sb.append(s[i]).append(s1[i1]);
                arrayList.add(sb.toString());
            }
        }
        arrayList.add(s3);
        arrayList.add(s4);

        //遍历集合元素
    //  PaiDuiShunXu(arrayList);
        //创建三个玩家集合一个底牌集合，进行发牌动作
        ArrayList<String> wj1=new ArrayList<String>();
        ArrayList<String> wj2=new ArrayList<String>();
        ArrayList<String> wj3=new ArrayList<String>();
        ArrayList<String> dipai=new ArrayList<String>();

        Collections.shuffle(arrayList);//洗牌
      //  PaiDuiShunXu(arrayList);
        faPai(arrayList, wj1, wj2, wj3, dipai);
        System.out.println('\n'+"牌堆");
        PaiDuiShunXu(arrayList);
        System.out.println('\n'+"------------玩家1手牌----------");
        PaiDuiShunXu(wj1);
        System.out.println('\n'+"---------玩家2手牌---------");

        PaiDuiShunXu(wj2);
        System.out.println('\n'+"---------玩家3手牌---------");
        PaiDuiShunXu(wj3);
        System.out.println('\n'+"-------底牌--------");
        PaiDuiShunXu(dipai);

    }

    private static void faPai(ArrayList<String> arrayList, ArrayList<String> wj1, ArrayList<String> wj2, ArrayList<String> wj3, ArrayList<String> dipai) {
        int i=1;
        for (String ss:arrayList   //发牌
             ) {
           if(i>51){  //底牌留4张
                dipai.add(ss);
            }else
                if(i%3==1){
                wj1.add(ss);
            }else if(i%3==2) {
                wj2.add(ss);
            }else if (i%3==0){
                wj3.add(ss);
            }
            i++;
        }
    }


    private static void PaiDuiShunXu(ArrayList<String> arrayList) {
        int i=1;
        for (String s5:arrayList
             ) {
            if (i%13!=0){
                System.out.print(s5+"  ");
                            }else
            {
                System.out.println(s5);
            }
            i++;
        }
    }
}
